#include <imbus.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>

IMUInt64 record_time ()
{
    struct timeval tv;
    gettimeofday (&tv, NULL);
    return (IMUInt64) tv.tv_sec * 1000000 + tv.tv_usec;
}

void print_time (IMUInt64 old_time)
{
    struct timeval tv;
    gettimeofday (&tv, NULL);

    IMUInt64 wasted = (IMUInt64) tv.tv_sec * 1000000 + tv.tv_usec - old_time;

    printf ("Spent %ld microseconds.\n", wasted);
}


int main (int argc, char *argv [])
{
    im_init (&argc, &argv);

    if (argc > 1) {
        IMMemoryChunk *chunk;
        IMIOChannel   *channel;
        IMUInt64 t;
        
        chunk = im_memory_chunk_new (0);
        channel = im_io_channel_new_file (argv[1], "r", 0);
        if (!channel) {
            printf ("Failed to open file.\n");
            return 1;
        }
        if (!im_memory_chunk_load (chunk, channel, -1, 0, 0)) {
            printf ("Failed to load file.\n");
            return 1;
        }
        printf ("Size = %d\n", im_memory_chunk_get_size (chunk));
        t = record_time ();
        printf ("CRC32 = 0x%08X\n", im_memory_chunk_get_checksum (chunk));
        print_time (t);
        im_object_unref (chunk);
        im_object_unref (channel);
    }

    return 0;
}
/*
vi:ts=4:nowrap:ai:expandtab
*/
